package com.googlecode.horncomb.orm.support.paged;

import java.util.Date;
import java.util.Collection;
import java.util.Locale;

import org.apache.commons.lang.Validate;


public class CollectionWrapperImpl<Type extends Collection<?>> implements
		CollectionWarpper<Type> {
	private static final long serialVersionUID = 2753349181354939193L;

	/** 集合 */
	private Type source;

	/** 数据装载时间 */
	protected Date refreshDate;

	/** 地区 */
	private Locale locale = null;

	public CollectionWrapperImpl() {
		super();
	}

	public CollectionWrapperImpl(Type source) {
		super();
		this.setSource(source);
	}

	public CollectionWrapperImpl(Type source, Locale local) {
		super();
		this.setSource(source);
		this.setLocale(locale);
	}

	/**
	 * Set the source list for this holder.
	 */
	public void setSource(Type source) {
		Validate.notNull(source);
		this.source = source;
		this.refreshDate = new Date();
	}

	/**
	 * Return the source list for this holder.
	 */
	public Type getSource() {
		return source;
	}

	/**
	 * get the count of elements
	 */
	public int getNrOfElements() {
		return this.getSource().size();
	}

	/**
	 * Return the last time the list has been fetched from the source provider.
	 */
	public Date getRefreshDate() {
		return refreshDate;
	}

	public Locale getLocale() {
		return this.locale;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}
}
